CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
PROJECT(stdtensor)

SET(CMAKE_CXX_STANDARD 14)

IF(USE_CLANG_TIDY)
    FIND_PROGRAM(CLANG_TIDY_EXE NAMES "clang-tidy")
    IF(CLANG_TIDY_EXE)
        SET(CMAKE_CXX_CLANG_TIDY clang-tidy)
    ENDIF()
ENDIF()

INCLUDE(cmake/strict.cmake)
INCLUDE(cmake/stdc++fs.cmake)
IF(MSVC)
    ADD_COMPILE_OPTIONS($<$<CONFIG:>:/MT> $<$<CONFIG:Debug>:/MTd>
                        $<$<CONFIG:Release>:/MT>)
    ADD_DEFINITIONS(-DGNU_UNUSED=)
ELSE()
    ADD_DEFINITIONS(-DGNU_UNUSED=[[gnu::unused]])
    ADD_DEFINITIONS(-DHAVE_CXXABI)
ENDIF()

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)

OPTION(BUILD_LIB "Build c lib." OFF)
IF(BUILD_LIB)
    INCLUDE(cmake/lib.cmake)
    BUILD_STDML_TENSOR_LIB(tensor)
ENDIF()

INSTALL(DIRECTORY include DESTINATION .)

OPTION(BUILD_TESTS "Build tests." OFF)
OPTION(BUILD_BENCHMARKS "Build benchmarks." OFF)
OPTION(BUILD_EXAMPLES "Build examples." OFF)
OPTION(HAVE_CUDA "Have cuda_runtime.h." OFF)

IF(HAVE_CUDA)
    INCLUDE_DIRECTORIES(${CUDA_HOME}/include)
    LINK_DIRECTORIES(${CUDA_HOME}/lib64)
ELSE()
    ADD_DEFINITIONS(-DUSE_FAKE_CUDA_RUNTIME)
ENDIF()

IF(BUILD_TESTS)
    ENABLE_TESTING()
    INCLUDE(cmake/tests.cmake)
ENDIF()

IF(BUILD_BENCHMARKS)
    INCLUDE(cmake/benchmarks.cmake)
ENDIF()

IF(BUILD_EXAMPLES)
    INCLUDE(cmake/examples.cmake)
ENDIF()

IF(BUILD_RELEASE)
    INCLUDE(cmake/pack.cmake)
ENDIF()
